import {
  queryRXDList,
  addRXD,
  getRXD,
  editRXD,
  removeRXD,
  rollbackRXD,
  queryCXDList,
  addCXD,
  getCXD,
  editCXD,
  removeCXD,
  rollbackCXD,
  queryYSJGList,
  addYSJG,
  getYSJG,
  editYSJG,
  removeYSJG,
  rollbackYSJG,
  queryQLList,
  addQL,
  getQL,
  editQL,
  removeQL,
  getBridgeFixedItem,
  rollbackQL,
  //养护管理
  GetCompany,
  GetClass,
  GetZClass,
  ReportSource,
  GetQueryProblem,
  Edit,
  Delete,
  CloseProblem,
  AssignProblem,
  GetMediafiles,
  /* 数据上报 */
  //一路一表
  GetQueryModelData,
  AddRoadMonth,
  EditRoadMonth,
  EditRollback,
  DelteleRoadMonth,
  //一桥一表
  yqybGetQueryModelData,
  yqybAddRoadMonth,
  yqybEditRoadMonth,
  yqybEditRollback,
  yqybDelteleRoadMonth,

  /* 统计分析 */
  // 一路一表
  GetQueryData,
  //一桥一表
  yqybGetQueryData,
} from '@/services/municipal';

export default {
  namespace: 'maintain',
  state: {
    rxdList: [],
    cxdList: [],
    ysjgList: [],
    rxddata: {},
    cxddata: {},
    ysjgdata: {},
    qldata: {},
    qlList: [],
    qlFixedItems: [],
    yhdwList: [], //养护单位
    sblyList: [], //上报来源
    wtlxList: [], //问题类型 大类
    wtlxZList: [], //问题类型 小类
    yhglTb: { data: [] }, //养护管理查询表格数据

    sjsbTb: [], //数据上报查询表格数据-一路一表
    sjsbTbYqyb: [], //数据上报查询表格数据-一桥一表

    error: '',
    data: {},
  },

  effects: {
    //人行道
    *fetchRXD({ payload }, { call, put }) {
      const response = yield call(queryRXDList, payload);

      if (!response.ErrorMessage) {
        yield put({
          type: 'queryRXD',
          payload: response.Data.rxd,
        });
      } else {
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },

    *addRXD({ payload, callback }, { call, put }) {
      const response = yield call(addRXD, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *getRXD({ payload, callback }, { call, put }) {
      const response = yield call(getRXD, payload);
      yield put({
        type: 'saveRXD',
        payload: response,
      });
      if (callback) callback(response);
    },

    *editRXD({ payload, callback }, { call, put }) {
      const response = yield call(editRXD, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *removeRXD({ payload, callback }, { call, put }) {
      const response = yield call(removeRXD, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *rollbackRXD({ payload, callback }, { call, put }) {
      const response = yield call(rollbackRXD, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    //车行道
    *fetchCXD({ payload }, { call, put }) {
      const response = yield call(queryCXDList, payload);

      if (!response.ErrorMessage) {
        yield put({
          type: 'queryCXD',
          payload: response.Data.cxd,
        });
      } else {
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },

    *addCXD({ payload, callback }, { call, put }) {
      const response = yield call(addCXD, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *getCXD({ payload, callback }, { call, put }) {
      const response = yield call(getCXD, payload);
      yield put({
        type: 'saveCXD',
        payload: response,
      });
      if (callback) callback(response);
    },

    *editCXD({ payload, callback }, { call, put }) {
      const response = yield call(editCXD, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *removeCXD({ payload, callback }, { call, put }) {
      const response = yield call(removeCXD, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *rollbackCXD({ payload, callback }, { call, put }) {
      const response = yield call(rollbackCXD, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    //雨水井盖
    *fetchYSJG({ payload }, { call, put }) {
      const response = yield call(queryYSJGList, payload);

      if (!response.ErrorMessage) {
        yield put({
          type: 'queryYSJG',
          payload: response.Data.ysjg,
        });
      } else {
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },

    *addYSJG({ payload, callback }, { call, put }) {
      const response = yield call(addYSJG, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *getYSJG({ payload, callback }, { call, put }) {
      const response = yield call(getYSJG, payload);
      yield put({
        type: 'saveYSJG',
        payload: response,
      });
      if (callback) callback(response);
    },

    *editYSJG({ payload, callback }, { call, put }) {
      const response = yield call(editYSJG, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *removeYSJG({ payload, callback }, { call, put }) {
      const response = yield call(removeYSJG, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *rollbackYSJG({ payload, callback }, { call, put }) {
      const response = yield call(rollbackYSJG, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    //桥梁
    *fetchQL({ payload }, { call, put }) {
      const response = yield call(queryQLList, payload);

      if (!response.ErrorMessage) {
        yield put({
          type: 'queryQL',
          payload: response.Data.ql,
        });
      } else {
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },

    *addQL({ payload, callback }, { call, put }) {
      const response = yield call(addQL, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *getQL({ payload, callback }, { call, put }) {
      const response = yield call(getQL, payload);
      yield put({
        type: 'saveQL',
        payload: response,
      });
      if (callback) callback(response);
    },

    *editQL({ payload, callback }, { call, put }) {
      const response = yield call(editQL, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *removeQL({ payload, callback }, { call, put }) {
      const response = yield call(removeQL, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },

    *fetchQLfixed({ payload, callback }, { call, put }) {
      const response = yield call(getBridgeFixedItem, payload);
      yield put({
        type: 'queryQLFixedItem',
        payload: response,
      });
      if (callback) callback(response);
    },

    *rollbackQL({ payload, callback }, { call, put }) {
      const response = yield call(rollbackQL, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback(response);
    },
    /* 养护管理 */
    // 获取养护单位
    *fetchGetCompany({ payload, callback }, { call, put }) {
      const response = yield call(GetCompany, payload);
      yield put({
        type: 'queryYhdw',
        payload: response,
      });
      if (callback) callback(response);
    },
    // 获取照片
    *fetchGetMediafiles({ payload, callback }, { call, put }) {
      const response = yield call(GetMediafiles, payload);
      if (callback) callback(response);
    },
    // 上报来源
    *fetchReportSource({ payload, callback }, { call, put }) {
      const response = yield call(ReportSource, payload);
      yield put({
        type: 'querySbly',
        payload: response,
      });
      if (callback) callback(response);
    },
    // 获取问题类型 大类
    *fetchGetClass({ payload, callback }, { call, put }) {
      const response = yield call(GetClass, payload);
      yield put({
        type: 'queryWtlx',
        payload: response,
      });
      if (callback) callback(response);
    },
    // 获取问题类型 小类
    *fetchGetZClass({ payload, callback }, { call, put }) {
      const response = yield call(GetZClass, payload);
      yield put({
        type: 'queryWtlxZ',
        payload: response,
      });
      if (callback) callback(response);
    },
    // 养护管理-查询
    *fetchGetQueryProblem({ payload, callback }, { call, put }) {
      const response = yield call(GetQueryProblem, payload);
      yield put({
        type: 'queryYhgl',
        payload: response,
      });
      if (callback) callback(response);
    },
    //删除记录
    *fetchYhglDelete({ payload, callback }, { call, put }) {
      const response = yield call(Delete, payload);
      if (callback) callback(response);
    },
    //结案记录
    *fetchYhglCloseProblem({ payload, callback }, { call, put }) {
      const response = yield call(CloseProblem, payload);
      if (callback) callback(response);
    },
    //编辑记录
    *fetchYhglEdit({ payload, callback }, { call, put }) {
      const response = yield call(Edit, payload);
      if (callback) callback(response);
    },
    //分派处理
    *fetchAssignProblem({ payload, callback }, { call, put }) {
      const response = yield call(AssignProblem, payload);
      if (callback) callback(response);
    },

    /* 数据上报 */
    //一路一表-数据条目查询
    *fetchGetQueryModelData({ payload, callback }, { call, put }) {
      const response = yield call(GetQueryModelData, payload);
      yield put({
        type: 'querySjsb',
        payload: response,
      });
      if (callback) callback(response);
    },
    //一路一表-新增记录
    *fetchYlybAdd({ payload, callback }, { call, put }) {
      const response = yield call(AddRoadMonth, payload);
      if (callback) callback(response);
    },
    //一路一表-编辑记录
    *fetchYlybEdit({ payload, callback }, { call, put }) {
      const response = yield call(EditRoadMonth, payload);
      if (callback) callback(response);
    },
    //一路一表-删除记录
    *fetchYlybDelete({ payload, callback }, { call, put }) {
      const response = yield call(DelteleRoadMonth, payload);
      if (callback) callback(response);
    },
    //一路一表-数据回退
    *fetchYlybEditRollback({ payload, callback }, { call, put }) {
      const response = yield call(EditRollback, payload);
      if (callback) callback(response);
    },

    //一桥一表-数据条目查询
    *fetchYqybGetQueryModelData({ payload, callback }, { call, put }) {
      const response = yield call(yqybGetQueryModelData, payload);
      yield put({
        type: 'yqybQuerySjsb',
        payload: response,
      });
      if (callback) callback(response);
    },
    //一桥一表-新增记录
    *fetchYqybAdd({ payload, callback }, { call, put }) {
      const response = yield call(yqybAddRoadMonth, payload);
      if (callback) callback(response);
    },
    //一桥一表-编辑记录
    *fetchYqybEdit({ payload, callback }, { call, put }) {
      const response = yield call(yqybEditRoadMonth, payload);
      if (callback) callback(response);
    },
    //一桥一表-删除记录
    *fetchYqybDelete({ payload, callback }, { call, put }) {
      const response = yield call(yqybDelteleRoadMonth, payload);
      if (callback) callback(response);
    },
    //一桥一表-数据回退
    *fetchYqybEditRollback({ payload, callback }, { call, put }) {
      const response = yield call(yqybEditRollback, payload);
      if (callback) callback(response);
    },

    /* 统计分析 */
    //一路一表-数据条目查询
    *fetchGetQueryData({ payload, callback }, { call, put }) {
      const response = yield call(GetQueryData, payload);
      yield put({
        type: 'queryTjfx',
        payload: response,
      });
      if (callback) callback(response);
    },
    //一桥一表-数据条目查询
    *fetchYqybGetQueryData({ payload, callback }, { call, put }) {
      const response = yield call(yqybGetQueryData, payload);
      yield put({
        type: 'yqybQueryTjfx',
        payload: response,
      });
      if (callback) callback(response);
    },
  },

  reducers: {
    queryRXD(state, action) {
      return {
        ...state,
        rxdList: action.payload,
      };
    },
    queryCXD(state, action) {
      return {
        ...state,
        cxdList: action.payload,
      };
    },
    queryYSJG(state, action) {
      return {
        ...state,
        ysjgList: action.payload,
      };
    },
    queryQL(state, action) {
      return {
        ...state,
        qlList: action.payload,
      };
    },
    queryQLFixedItem(state, action) {
      return {
        ...state,
        qlFixedItems: action.payload,
      };
    },
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
    saveRXD(state, action) {
      return {
        ...state,
        rxddata: action.payload,
      };
    },
    saveCXD(state, action) {
      return {
        ...state,
        cxddata: action.payload,
      };
    },
    saveYSJG(state, action) {
      return {
        ...state,
        ysjgdata: action.payload,
      };
    },
    saveQL(state, action) {
      return {
        ...state,
        qldata: action.payload,
      };
    },
    //养护单位
    queryYhdw(state, action) {
      return {
        ...state,
        yhdwList: action.payload,
      };
    },
    //上报来源
    querySbly(state, action) {
      return {
        ...state,
        sblyList: action.payload,
      };
    },
    //问题类型 大类
    queryWtlx(state, action) {
      return {
        ...state,
        wtlxList: action.payload.data,
      };
    },
    //问题类型 小类
    queryWtlxZ(state, action) {
      return {
        ...state,
        wtlxZList: action.payload,
      };
    },
    //养护管理-查询
    queryYhgl(state, action) {
      return {
        ...state,
        yhglTb: action.payload,
      };
    },

    //数据上报-一路一表-查询
    querySjsb(state, action) {
      return {
        ...state,
        sjsbTb: action.payload,
      };
    },
    //数据上报-一桥一表-查询
    yqybQuerySjsb(state, action) {
      return {
        ...state,
        sjsbTbYqyb: action.payload,
      };
    },

    //统计分析-一路一表-查询
    queryTjfx(state, action) {
      return {
        ...state,
        sjsbTb: action.payload,
      };
    },
    //统计分析-一桥一表-查询
    yqybQueryTjfx(state, action) {
      return {
        ...state,
        sjsbTbYqyb: action.payload,
      };
    },
  },
};
